/**
 * @Date 2023-02-21 10:03:49
 * @Remark
 */

// react
import React from "react";
// lib
import { Space, Button, Popconfirm } from "antd";
// store
import { state } from "./state";
import { delProCategory } from "./controller";

// controller
// import { delAdmin } from "./controller";

const TableColumns = [
  {
    title: "分类id",
    dataIndex: "categoryId",
  },
  {
    title: "分类名称",
    dataIndex: "categoryName",
  },

  {
    title: "上级分类",
    render:(el:CategoryDto) =>{
      if (el && el.parentCategoryId) {
        
        const  temp = state.getLongList().find(item => item.categoryId === el.parentCategoryId)
        return temp?.categoryName
      }
      return ""
      // const tempArra = state.getLongList()
      // if (tempArra.length > 0) {

      // return 123
    }
  },
  {
    title: "操作",
    key: "action",
    fixed: "right" as any,
    render: (el: CategoryDto) => {
      const edit = () => {
        state.editModal = el;
      };

      const del = () => {
        delProCategory(el.categoryId);
      };

      return (
        <Space>
          <Button size="small" type="primary" ghost onClick={edit}>
            编辑
          </Button>

          <Popconfirm title={"确定要删除吗？"} onConfirm={del}>
            <Button size="small" danger ghost>
              删除
            </Button>
          </Popconfirm>
        </Space>
      );
    },
  },
];

export default TableColumns;
